<template>
  <a-modal
    title="選擇生效賬單"
    :width="600"
    :visible="visible"
    class="model-yz"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <div class="content">
      <a-row>
        <a-col :span="4">
        </a-col>
        <a-col :span="16">
          <a-radio-group v-model="value" @change="onChange">
            <a-radio
              @click="radioSClick(item)"
              :style="radioStyle"
              :value="item.qsNum"
              :disabled="item.disabled"
              v-for="(item,index) in itemList"
              :key="index">
              <span class="tt">{{ item.qsNum }}期賬單</span> - <span class="tt-c">账单周期:{{ item.rentStartDate }}-{{ item.rentEndDate }}</span>
            </a-radio>
          </a-radio-group>
        </a-col>
        <a-col :span="4">
        </a-col>
      </a-row>
    </div>
  </a-modal>
</template>

<script>
import { getBillListByLeaseId } from '@/api/modular/main/housebill/houseBillManage'

export default {
  data() {
    return {
      visible: false,
      confirmLoading: false,
      itemList: [],
      selectList: [],
      value: '',
      radioStyle: {
        display: 'block',
        height: '30px',
        lineHeight: '30px'
      },
      item: {}
    }
  },
  methods: {
    // 初始化方法
    select(leaseId, checkedValue) {
      this.visible = true
      this.checkedValue = checkedValue
      this.initDataList(leaseId)
    },
    initDataList(leaseId) {
      getBillListByLeaseId(leaseId).then((res) => {
        if (res.code === 200) {
          this.itemList = res.data
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    onChange(e) {
      console.log('radio checked', e.target.value)
    },
    radioSClick(item) {
      this.item = item
    },
    /**
     * 提交表单
     */
    handleSubmit() {
      if (this.value === '') {
        this.$message.error('請選擇生效賬單')
        return
      }
      this.$emit('ok', this.item)
      this.handleCancel()
    },
    handleCancel() {
      this.visible = false
      this.itemList = []
      this.selectList = []
      this.value = ''
      this.item = {}
    }
  }
}
</script>

<style lang="less" scoped>
.content{
  padding: 6px 20px;
  .tt{
    font-weight: bold;
  }
  .tt-c{
    font-size: 16px;
  }
}
.model-yz  /deep/ .ant-modal-content{
    height: 600px;
    overflow-y:scroll;
    overflow-x: hidden;
}
.model-yz  /deep/ .ant-modal-content::-webkit-scrollbar {
  width: 4px;
}
.model-yz  /deep/ .ant-modal-content::-webkit-scrollbar-track {
 background-color:rgb(250, 241, 241);
}
.model-yz  /deep/ .ant-modal-content::-webkit-scrollbar-thumb {
 background-color:rgb(205, 209, 205);
}
</style>
